--
-- Author: mm
-- Date: 2018-05-08 11:24:48
--
-- ItemGotWayRender
--

local ClassRef = app.mvc.createRenderClass(...)

local string_split = string.split

--data =
function ClassRef.createWithData(data, node)
    local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.ItemGotWayNode))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

--
function ClassRef:init(data)
    self.super.init(self, data)
    self:setContentSize( self._ui.Panel:getContentSize() )
    self._ui.Button:addClickEventListener(function()
        if 0 ~= self._featureId then
            executeFunc( self._onClick, "goto_feature", { feature = self._featureId, param = self._param} )
        end
    end)
    self:refresh()
end

-- data = { 10053|resource_5 }
-- 10053        -- funcId
-- resource_5   -- nameStr
function ClassRef:refresh()
    if self._data then
        self:setVisible( true )
        local data = self._data
        local tempList = string_split( data, "|" )
        self._featureId = tonumber( tempList[1] )
        self._ui.name:setString( L(tempList[2]) )
        if tempList[3] then
            self._param = string_split(tempList[3], "#")
        end
        self._ui.Button:setBright( 0 ~= self._featureId )
    else
        self:setVisible( false )
    end
end

function ClassRef:onBtnClick(cb)
    self._onClick = cb
end

return ClassRef
